package io.gitee.chearnee.fw.common.utils;

import lombok.experimental.UtilityClass;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 12/5/2022 6:01 PM
 */
@UtilityClass
public class ObjectUtil {
    private static final Set<Class<?>> IGNORE_CLASS = new HashSet<>();

    static {
        // initIgnoreClass
        IGNORE_CLASS.add(Byte.class);
        IGNORE_CLASS.add(Short.class);
        IGNORE_CLASS.add(Integer.class);
        IGNORE_CLASS.add(Long.class);
        IGNORE_CLASS.add(Float.class);
        IGNORE_CLASS.add(BigDecimal.class);
        IGNORE_CLASS.add(Double.class);
        IGNORE_CLASS.add(Boolean.class);
        IGNORE_CLASS.add(Character.class);
    }

    public static boolean inIgnoreClass(Class<?> cls) {
        return IGNORE_CLASS.contains(cls);
    }

    public static boolean isBean(Object obj) {
        if (Objects.isNull(obj) || inIgnoreClass(obj.getClass()) || obj instanceof Map) {
            return false;
        }
        if (obj instanceof String) {
            return false;
        }
        if (obj instanceof Number) {
            return false;
        }
        if (obj instanceof Iterable) {
            return false;
        }
        return !obj.getClass().isArray();
    }

}
